﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using University.Workshop.Business;

namespace University.Workshop.Presenters.WaterReadingKardexMeassure.Modify
{
    public class PresenterModifyKardexMeasure
    {
        IModifyKardexMeasure view;
        Model.Kardex kardex;

        public PresenterModifyKardexMeasure(IModifyKardexMeasure view, Model.Kardex kardex)
        {
            this.view = view;
            this.kardex = kardex;
        }

        public void UpdateViewData()
        {
            view.Name = kardex.Person.Names;
            view.LastName = kardex.Person.LastNames;
            view.Square = kardex.AllotmentModel.SquareId;
            view.Allotment = kardex.AllotmentModel.AllotmentName;
            view.WaterMeasure = kardex.WaterMeasurer;
        }

        public void ChangeMeasure()
        {
            try
            {
                kardex.WaterMeasurer = view.WaterMeasure;
                Model.WaterReadingControl newWaterReading = new Model.WaterReadingControl()
                                                            {
                                                                CurrentMeasurerRead = view.CurrentRead
                                                            };
                ManagerWaterReadingControl.UpdateKardexAndGenerateReading(kardex, newWaterReading);
                view.NotifySystemMessage("El medidor fue cambiado exitosamente");
                view.ReturnSearchKardexMeasure();
            }
            catch (Exception ex)
            {
                view.NotifyErrorMessage(ex.Message);
            }
        }
  
    }
}
